import {defineStore} from 'pinia'
import {getLeaderUserApi} from "@/api/User";

export const usePAUserOneStore = defineStore('PAUserOne', {
    state: () => {
        return {
            tabledata: []
        }
    },
    getters: {},
    actions: {
        setTableData(data) {
            this.tabledata.push(data)
        },
        getTableData(id) {
            this.tabledata = []
            getLeaderUserApi(id).then(res => {
                this.tabledata.push({
                    id: res['data'].userId,
                    name: res['data'].userName,
                    position: "领导",
                    status: res['data'].statusId,
                    isDisabled: true
                })
            })
        },
        deleteUser(tabledata) {
            // 表示先获取这个元素的下标，然后从这个下标开始计算，删除长度为1的元素
            this.tabledata.splice(this.tabledata.indexOf(tabledata), 1)
        },
        judgeData() {
            return this.tabledata.length != 0
        }
    }

})
